var app = getApp()
 Page({
data: { 
 catlist: [
{ name:"悠悠","location":"菊苑"},{ name:"蛋黄","location":"菊苑"},{ name:"巨蛋","location":"菊苑"},{ name:"豆丁","location":"图书馆"},{ name:"小米","location":"学科楼"},{ name:"打人橘","location":"菊苑"},{ name:"玉米","location":"菊苑"},{ name:"苞谷","location":"菊苑"},{ name:"柠檬","location":"图书馆"},],swiperNav:{i:0,arr:[{v:0,txt:"所有"},{v:1,txt:"不定"},{v:2,txt:"栗子山、图书馆"},{v:3,txt:"西门"},{v:4,txt:"文科楼"},{v:5,txt:"教三"},{v:6,txt:"新天地"},{v:7,txt:"美宜佳、新天地"},{v:8,txt:"学科楼"},{v:9,txt:"梅苑"},{v:10,txt:"菊苑"},{v:11,txt:"校之友"},{v:12,txt:"柳苑"},{v:13,txt:"南北荷"},{v:14,txt:"青教"},{v:15,txt:"北荷"},{v:16,txt:"图书馆"},{v:17,txt:"美宜佳"},{v:18,txt:"南三附近"},{v:19,txt:"南荷"},{v:20,txt:"大活"},{v:21,txt:"李苑"},{v:22,txt:"李苑、柳苑"}]},    
    screenWidth: 0,
    screenHeight: 0,
    imgwidth: 0,
    imgheight: 0,
    url: app.globalData.url,
  },
  
  swiperNav: function (e) {
    console.log(e);
    /*获取可视窗口宽度*/
    var w = wx.getSystemInfoSync().windowWidth;
    var leng = this.data.swiperNav.arr.length;
    var i = e.target.dataset.i;
    var disX = (i - 2) * w / leng;

    if(this.data.swiperNav.i === 0) {
      wx.setStorageSync('catlist', this.data.catlist);
    }
    if (i != this.data.swiperNav.i) {
      this.setData({
        'swiperNav.i': i
      })
    }
    this.setData({
      'swiperNav.x': disX
    })
    if(i == 0) {
      this.setData({catlist: wx.getStorageSync('catlist')});
    } else {
      let loc = this.data.swiperNav.arr[i].txt;
      let catlist = wx.getStorageSync('catlist').filter(item => item.location === loc)
      this.setData({
        catlist:catlist
      })
    }
  },
  //end

  onPullDownRefresh:function(){
    wx.stopPullDownRefresh()
  },

  //转发跳转页面设置
  onLoad: function (options) {
    if (options.pageId) {
      
      wx.navigateTo({
        url: '/pages/cats/' + options.pageId + '/' + options.pageId,
      })
    }
  },

  //转发此页面的设置
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      path: 'pages/index/index',  // 路径，传递参数到指定页面。
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  },

  // 搜索栏输入名字后页面跳转
  bindconfirmT: function (e) {
    console.log("e.detail.value");
    if(e.detail.value) {
    
    wx.navigateTo({
      url: '/pages/cats/' + e.detail.value + '/' + e.detail.value,
    })
  }
  }


})

